<route lang="json5" type="page">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '管家巡检',
    navigationBarBackgroundColor: '#fff',
  },
}
</route>

<template>
  <view class="pb-safe">
    <view class="px-3 pt-3">
      <image :src="inspectionPointIcon" class="w-4 h-4" mode="scaleToFill" />
      日常管家巡检
    </view>

    <view class="py-3 text-sm" v-show="!loading">
      <wd-cell
        v-for="(item, i) in taskList"
        :key="item.id"
        :title="`${i + 1}. ${item.pointContentName}`"
        is-link
        border
      />
    </view>

    <view class="px-3" v-show="!loading">
      <view class="w-80px center py-1 rounded-2 bg-amber mb-2 text-xs">顺路任务</view>
      <view class="p-2 bg-[#d9d6c3] rounded-2 text-xs">
        <view class="leading-relaxed" v-for="(item, i) in onWayTaskList" :key="item.id">
          {{ i + 1 }}、{{ item.aiName }}
          <wd-text
            class="ml-auto"
            v-if="item.aiName.includes('工单')"
            type="primary"
            text="工单详情>"
          ></wd-text>
        </view>
      </view>
    </view>

    <RobotAi />
  </view>
</template>

<script lang="ts" setup>
import inspectionPointIcon from './static/inspection-point.svg'
import { listByPointId, onWayTask } from './api/index'
import RobotAi from '@/components/robotAI.vue'

const loading = ref(true)
const insnId = ref('')
onLoad(async (options) => {
  insnId.value = options.id

  getListByTask()
  getOnWayTask()
})

const taskList = ref([])
async function getListByTask() {
  try {
    loading.value = true
    const { rows } = await listByPointId(insnId.value)
    taskList.value = rows.filter((item) => item !== null)
    loading.value = false
  } catch (error) {}
}

const onWayTaskList = ref([])
async function getOnWayTask() {
  try {
    const { rows } = await onWayTask(insnId.value)
    onWayTaskList.value = rows.filter((item) => item !== null)
  } catch (error) {}
}
</script>

<style lang="scss" scoped>
//
</style>
